
import 'package:flutter/material.dart';
import 'package:untitled/pages/view/home/item_page.dart';
import 'package:untitled/pages/view/home/mine_page.dart';



class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}
// 首页面
class _HomePageState extends State<HomePage> {
  // 当前选中的标识
  int _currentIndex = 0;
  PageController _pageController = new PageController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: double.infinity,
        height: double.infinity,
        child: PageView(
          // 不可左右滑动
          physics: NeverScrollableScrollPhysics(),
          controller: _pageController,
          children: [
            ItemPageDemo(flag: 1),
            ItemPageDemo(flag: 2),
            ItemPageDemo(flag: 3),
            MineMainPage(),
          ],
        ),

      ),
      bottomNavigationBar: BottomNavigationBar(
        // 当前选中的item 默认为0
        currentIndex: _currentIndex,
        onTap: (int value){
          setState(() {
            _currentIndex = value;
            _pageController.jumpToPage(value);
          });
        },
        // 显示文字
        type: BottomNavigationBarType.fixed,
        // 未选中颜色
        unselectedItemColor: Colors.blueAccent,
        // 选中颜色
        selectedItemColor: Colors.redAccent,
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home),label: "首页"),
          BottomNavigationBarItem(icon: Icon(Icons.five_g),label: "发现"),
          BottomNavigationBarItem(icon: Icon(Icons.message),label: "消息"),
          BottomNavigationBarItem(icon: Icon(Icons.person),label: "我的"),
        ],
      ),
    );
    
  }
}